package com.smm.util;


import java.sql.Connection;  
import java.sql.DriverManager;  
import java.sql.PreparedStatement;  
import java.sql.SQLException;  

import java.util.*;
import com.smm.util.PropertiesReader;

public class DBHelper {

    public Connection conn = null;  
    public PreparedStatement pst = null;  
  
    public DBHelper(String sql) {  
        try {  

            PropertiesReader reader=new PropertiesReader("/db.properties");

            String port=reader.getValue("db.Port");

        	String databaseName=reader.getValue("db.databaseName");
        	String user=reader.getValue("db.UserName");
        	String password=reader.getValue("db.Password");

        	String url="jdbc:mysql://"+port+"/"+databaseName;

            Class.forName("com.mysql.jdbc.Driver");//指定连接类型  
            conn = DriverManager.getConnection(url, user, password);//获取连接  
            pst = conn.prepareStatement(sql);//准备执行语句  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
  
    public void close() {  
        try {  
            this.conn.close();  
            this.pst.close();  
        } catch (SQLException e) {  
            e.printStackTrace();  
        }  
    }  
}